#ifndef __RAYTRACER_H__
#define __RAYTRACER_H__

// The main ray tracer.

#include "scene/scene.h"
#include "scene/ray.h"

class RayTracer
{
public:
    RayTracer();
    ~RayTracer();

    vec3f trace( Scene *scene, double x, double y );
	vec3f traceRay( Scene *scene, const ray& r, const vec3f& thresh, int depth );


	void getBuffer( unsigned char *&buf, int &w, int &h );
	void getIntensityBuffer( unsigned char *&buf, int &w, int &h );
	double aspectRatio();
	void traceSetup( int w, int h );
	void traceLines( int start = 0, int stop = 10000000 );
	void tracePixel( int i, int j );
	vec3f adaptiveTrace( Scene *scene, double x, double y, double divWidth, double divHeight, double threshold, int depth, int &numOfRays);

	inline void setDepth(int depth) { traceDepth = depth;};
	inline void setSuperSamplingSize(int samplingSize) { superSamplingSize = samplingSize;};
	inline void setJitterEnabled(bool enable) { isJitterEnabled = enable;};
	inline void setAdaptiveSamplingEnabled(bool enable) { isAdaptiveSamplingEnabled = enable; };

	bool loadScene( char* fn );

	bool sceneLoaded();

private:
	unsigned char *buffer;
	unsigned char *intensity_buffer;
	int buffer_width, buffer_height;
	int bufferSize;
	int traceDepth;
	int superSamplingSize;

	bool isJitterEnabled;
	bool isAdaptiveSamplingEnabled;

	Scene *scene;

	bool m_bSceneLoaded;
};

#endif // __RAYTRACER_H__
